package com.jz.digital.converter;

import com.jz.digital.bean.UserInfo;
import com.jz.digital.utils.GsonUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.List;

/**
 * ================================================
 * Created: WangYong
 * Date: 2024/11/25
 * Description:
 * ================================================
 */
public class PermissionBeanConverter implements PropertyConverter<List<UserInfo.PermissionBean>, String> {


    @Override
    public List<UserInfo.PermissionBean> convertToEntityProperty(String databaseValue) {
        List<UserInfo.PermissionBean> points = null;
        try {
            points = new Gson().fromJson(databaseValue, new TypeToken<List<UserInfo.PermissionBean>>() {
            }.getType());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return points;
    }

    @Override
    public String convertToDatabaseValue(List<UserInfo.PermissionBean> entityProperty) {
        String item = "";
        try {
            item = GsonUtil.toJson(entityProperty);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return item;
    }
}